<template>
  <div class="login-container">
    <div class="login-box">
      <div class="login-title">
        校园共享单车管理后台
      </div>
      <el-form
        ref="loginRef"
        :model="loginForm"
        :rules="rules"
        label-width="80px"
        class="login-form"
      >
        <el-form-item
          label="用户名"
          prop="username"
        >
          <el-input
            v-model="loginForm.username"
            placeholder="请输入用户名"
          />
        </el-form-item>
        <el-form-item
          label="密码"
          prop="password"
        >
          <el-input
            v-model="loginForm.password"
            type="password"
            placeholder="请输入密码"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            class="login-btn"
            @click="onLogin"
          >
            登录
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'

const router = useRouter()
const loginRef = ref()
const loginForm = ref({ username: '', password: '' })
const rules = {
  username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
  password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
}
const onLogin = () => {
  loginRef.value.validate((valid: boolean) => {
    if (valid) {
      // 模拟登录
      if (loginForm.value.username === 'admin' && loginForm.value.password === 'admin') {
        ElMessage.success('登录成功')
        router.push('/')
      } else {
        ElMessage.error('用户名或密码错误')
      }
    }
  })
}
</script>

<script lang="ts">
export default { name: 'LoginPage' }
</script>

<style scoped>
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e0e7ff 0%, #f0f2f5 100%);
}
.login-box {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 32px rgba(0,0,0,0.08);
  padding: 48px 40px 32px 40px;
  min-width: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.login-title {
  font-size: 26px;
  font-weight: 700;
  color: #333;
  margin-bottom: 32px;
  letter-spacing: 2px;
}
.login-form {
  width: 100%;
}
.login-btn {
  width: 100%;
  font-size: 16px;
  letter-spacing: 2px;
}
</style> 